<template>
  <cement-content
    :title="porepressureTitle"
    :search="boreholeSearch"
    @getData="getPorePressure"
    @deleteRow="deletePorePressure"
    @submitUpdate="submitPorepressureUpdate"
    @submitSearchModel="submitPorepressurSearchModel">
  </cement-content>
</template>

<script>
import cementContent from '@/components/cement-content'
import {getPorePressure,deletePorePressure, updatePorePressure} from '@/api/module/porepressure'
import {get} from 'lodash'
import {mapGetters, mapMutations} from 'vuex'
import {PORE_PRESSURE_TITLE,  BOREHOLE_SEARCH_DATA, FIRST_PAGE} from '@/util/constant'

export default {
  name: 'index',
  components: {
    cementContent
  },
  data () {
    return {
      porepressureTitle: PORE_PRESSURE_TITLE,
      boreholeSearch: BOREHOLE_SEARCH_DATA
    }
  },
  mounted () {
    this.getPorePressure()
  },
  methods: {
    ...mapMutations([
      'changeTableData',
      'changeTotal',
      'closeDialog',
      'changeCurrentPage',
      'changePageSize',
      'updatePorePressure'
    ]),
    getPorePressure () {
      getPorePressure(this.currentPageGetters - 1, this.pageSizeGetters, this.searchModelGetters).then((res) => {
        this.changeTableData(get(res, 'data.data.content', []))
        this.changeTotal(get(res, 'data.data.totalElements', 0))
      })
    },
    deletePorePressure (row) {
      
      if (get(row, 'id')) {
        deletePorePressure(row['id'])
      }
    },
    submitPorepressurSearchModel () {
      this.changePageSize(FIRST_PAGE)
      this.getPorePressure()
    },
    submitPorepressureUpdate () {
      if (get(this.updateModelGetters, 'id')) {
        updatePorePressure(get(this.updateModelGetters, 'id'), this.updateModelGetters).then(
          this.closeDialog()
        )
      }
    },

  },
  computed: {
    ...mapGetters([
      'pageSizeGetters',
      'currentPageGetters',
      'searchModelGetters',
      'updateModelGetters'
    ])
  }
}
</script>
